package com.secf.service.port.hpy.hys.test.day3;

import java.util.Arrays;

/**
 * @Author ms
 * @Date 2024-08-08
 */
public class AdvancedArrayTest {
    public static void main(String[] args) {
        // 测试可变参数
        System.out.println("Testing Varargs:");
        printNumbers(10, 20, 30, 40);

        // 测试数组与集合转换
        String[] array = {"A", "B", "C"};
        System.out.println("Testing Arrays.asList:");
        System.out.println(Arrays.asList(array));

        // 测试深拷贝与浅拷贝
        int[] original = {1, 2, 3};
        int[] shallowCopy = original;
        int[] deepCopy = original.clone();
        original[0] = 99;
        System.out.println("Shallow copy: " + Arrays.toString(shallowCopy));
        System.out.println("Deep copy: " + Arrays.toString(deepCopy));

        // 测试Stream API
        System.out.println("Testing Stream API:");
        int[] numbers = {1, 2, 3, 4, 5};
        int sum = Arrays.stream(numbers).sum();
        System.out.println("Sum: " + sum);
    }

    public static void printNumbers(int... numbers) {
        for (int number : numbers) {
            System.out.println(number);
        }
    }
}
